package shopping.demo.util;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Component;

import java.util.UUID;

@Component
public class TokenUtils {
    @Autowired
    private RedisUtil redisUtil;

    private static final String TOKEN_PREFIX = "authentication_";
    public static final String TOKEN_HEADER = "token";

    public String createToken() {
        String token = TOKEN_PREFIX + UUID.randomUUID().toString();
        //将token存入redis中
        redisUtil.set(token,token);
        return token;
    }

    public Boolean checkToken(String token) {
        return redisUtil.delete(token);
    }
}
